package com.npy.reggie.contorller.old;

//@Slf4j
//@RestController
//@RequestMapping("/employee")
public class EmployeeControllerOld {

    /*@Autowired
    private EmployeeService employeeService ;


    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest  request,
                             @RequestBody Employee employee){
           employee.setPassword(DigestUtils
                   .md5DigestAsHex(employee.getPassword().getBytes()));

        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();

        lqw.eq(Employee::getUsername,employee.getUsername());

        Employee deployed = employeeService.getOne(lqw);

        if (deployed==null || !deployed.getPassword().equals(employee.getPassword())){
            return R.error("错了");
        }

        if (deployed.getStatus()==0){
            return R.error("不给你登");
        }

        request.getSession().setAttribute("employee",deployed.getId());

        return R.success(deployed);

    }

    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        request.getSession().invalidate();
        return R.success("这就不行了？");
    }

    @PostMapping
    public R<String> saveEmployee(HttpServletRequest request,@RequestBody Employee employee){
        log.info("{}",employee);
        employee.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
        employee.setCreateTime(LocalDateTime.now());
        employee.setUpdateTime(LocalDateTime.now());
        long emp = (long) request.getSession().getAttribute("employee");
        employee.setCreateUser(emp);
        employee.setUpdateUser(emp);
        employeeService.save(employee);

        return R.success("添加成功");

    }

    @GetMapping("/page")
    public R<Page<Employee>> page(int page , int pageSize, String name){
        log.info("page数据{},{},{}",page,pageSize,name);

        Page<Employee> pageInfo = new Page<>(page,pageSize);


        LambdaQueryWrapper<Employee> lqm = new LambdaQueryWrapper<>();

        lqm.like(name!=null&&name.length()!=0,Employee::getName,name);

        lqm.orderByDesc(Employee::getCreateTime);
        Page<Employee> page1 = employeeService.page(pageInfo,lqm);

        for (Employee record : page1.getRecords()) {
            record.getNewTypeId();
            log.info("typeId{}",record.getNewTypeId());
        }



        log.info("typeId{}",page1.getRecords());
        return R.success(page1);
    }


    @PutMapping
    public R<String> upDataEmployee(HttpServletRequest request,@RequestBody Employee employee){
        employee.setUpdateUser((Long) request.getSession().getAttribute("employee"));
        employee.setUpdateTime(LocalDateTime.now());


        employee.setId(Long.parseLong(employee.getNewTypeId()));

        employeeService.updateById(employee);

        employeeService.updateById(employee);
        log.info("修改状态{}",employee);
        return R.success("修改成功");
    }

    @GetMapping("/{id}")
    public R<Employee> reDate (@PathVariable Long id){

        return R.success(employeeService.getById(id));
    }*/
}
